<template>
  <v-data-table :headers="headers" 
  :items="desserts" 
  sort-by="calories" 
  class="elevation-1"
  calculate-widths>
    <template v-slot:top>
      <v-toolbar flat>
        <v-toolbar-title>子流水</v-toolbar-title>
        <v-divider class="mx-4" inset vertical></v-divider>
        <v-spacer></v-spacer>
        <v-dialog v-model="dialog" max-width="800px">
          <template v-slot:activator="{ on }">
            <v-btn color="primary" dark class="mb-2" v-on="on">新增子流水</v-btn>
          </template>
          <v-card>
            <v-card-title>
              <span class="headline">{{ formTitle }}</span>
            </v-card-title>

            <v-card-text>
              <v-container>
                <v-row>
                  <v-col cols="12" sm="6" md="4">
                    <v-text-field v-model="editedItem.bankid" label="银行号"></v-text-field>
                  </v-col>
                    <v-col cols="12" sm="6" md="4">
                        <v-select
                                :items="moduleItems"
                                label="所属子系统"
                                v-model="editedItem.subsys"
                                item-text="name"
                                item-value="attributes"
                        ></v-select>
                    </v-col>

                  <v-col cols="12" sm="6" md="4">
                    <v-text-field v-model="editedItem.accdate" label="会计核算日期"></v-text-field>
                  </v-col>
                   <v-col cols="12" sm="6" md="4">
                    <v-text-field v-model="editedItem.accseqno" label="会计核算流水号"></v-text-field>
                  </v-col>
                <v-col cols="12" sm="6" md="4">
                    <v-text-field v-model="editedItem.kltrnseq" label="核心流水号"></v-text-field>
                </v-col>
                  <!--<v-col cols="12" sm="6" md="4">
                     <v-select 
                     :items="brcItems" 
                     label="交易机构" 
                     v-model="editedItem.brctran"
                      item-text="brcname"
                      item-value="brc"
                     ></v-select>
                  </v-col>-->
                    <v-col cols="12" sm="6" md="4">
                        <v-text-field v-model="editedItem.klseqno" label="核心流水号序号"></v-text-field>
                    </v-col>
                    <v-col cols="12" sm="6" md="4">
                        <v-text-field  label="会计分户记账标志"></v-text-field>
                    </v-col>

                    <v-col cols="12" sm="6" md="4">
                        <v-text-field v-model="editedItem.tranamt" label="交易金额"></v-text-field>
                    </v-col>

                    <v-col cols="12" sm="6" md="4">
                        <v-text-field v-model="editedItem.prdcode" label="产品代码"></v-text-field>
                    </v-col>

                    <v-col cols="12" sm="6" md="4">
                      <v-select :items="tranentnoItems" 
                      label="交易事件" 
                      v-model="editedItem.entcode"
                      item-text="tranevntnm"
                      item-value="tranentno"
                      ></v-select>
                  </v-col>
                    <!-- <v-col cols="12" sm="6" md="4">
                        <v-text-field v-model="editedItem.entcode" label="事件代码"></v-text-field>
                    </v-col> -->

                    <v-col cols="12" sm="6" md="4">
                        <v-text-field v-model="editedItem.ccy" label="币种"></v-text-field>
                    </v-col>

                  <v-col cols="12" sm="6" md="4">
                    <v-text-field v-model="editedItem.custno" label="客户号"></v-text-field>
                  </v-col>

                    <v-col cols="12" sm="6" md="4">
                        <v-text-field v-model="editedItem.accno" label="内部账号"></v-text-field>
                    </v-col>

                    <v-col cols="12" sm="6" md="4">
                        <v-text-field v-model="editedItem.prdaccno" label="产品账号"></v-text-field>
                    </v-col>

                    <v-col cols="12" sm="6" md="4">
                        <v-text-field v-model="editedItem.prdaccname" label="产品账号户名"></v-text-field>
                    </v-col>

                  
                    <v-col cols="12" sm="6" md="4">
                        <v-select
                                :items="crflgItems"
                                label="钞汇标志"
                                v-model="editedItem.crflg"
                                item-text="name"
                                item-value="attributes"
                        ></v-select>
                    </v-col>

                    <v-col cols="12" sm="6" md="4">
                        <v-text-field v-model="editedItem.brcadsc" label="归属机构"></v-text-field>
                    </v-col>

                    <v-col cols="12" sm="6" md="4">
                        <v-text-field v-model="editedItem.vouno" label="凭证号"></v-text-field>
                    </v-col>

                    <v-col cols="12" sm="6" md="4">
                        <v-text-field v-model="editedItem.voutyp" label="凭证种类"></v-text-field>
                    </v-col>

                    <v-col cols="12" sm="6" md="4">
                        <v-text-field v-model="editedItem.accnoa" label="对方账号"></v-text-field>
                    </v-col>

                    <v-col cols="12" sm="6" md="4">
                        <v-text-field v-model="editedItem.accnma" label="对方户名"></v-text-field>
                    </v-col>

                    <v-col cols="12" sm="6" md="4">
                        <v-text-field v-model="editedItem.banknoa" label="对方行号"></v-text-field>
                    </v-col>

                    <v-col cols="12" sm="6" md="4">
                        <v-text-field v-model="editedItem.banknma" label="对方行名"></v-text-field>
                    </v-col>

                    <v-col cols="12" sm="6" md="4">
                        <v-text-field v-model="editedItem.ccya" label="对方币种"></v-text-field>
                    </v-col>

                    <v-col cols="12" sm="6" md="4">
                        <v-text-field v-model="editedItem.crflga" label="对方钞汇标识"></v-text-field>
                    </v-col>

                    <v-col cols="12" sm="6" md="4">
                        <v-text-field v-model="editedItem.acchngno" label="待销账编号"></v-text-field>
                    </v-col>

                    <v-col cols="12" sm="6" md="4">
                        <v-text-field v-model="editedItem.hngacctyp" label="待销账种类"></v-text-field>
                    </v-col>

                    <v-col cols="12" sm="6" md="4">
                        <v-text-field v-model="editedItem.hngopflg" label="待销账操作"></v-text-field>
                    </v-col>

                    <v-col cols="12" sm="6" md="4">
                        <v-text-field v-model="editedItem.hngduedate" label="挂账到期日"></v-text-field>
                    </v-col>

                    <v-col cols="12" sm="6" md="4">
                        <v-text-field v-model="editedItem.hngamt" label="挂账金额"></v-text-field>
                    </v-col>

                    <v-col cols="12" sm="6" md="4">
                        <v-text-field v-model="editedItem.canamt" label="销账金额"></v-text-field>
                    </v-col>

                    <v-col cols="12" sm="6" md="4">
                        <v-text-field v-model="editedItem.speclsflg" label="特殊清算标志"></v-text-field>
                    </v-col>

                    <v-col cols="12" sm="6" md="4">
                        <v-text-field v-model="editedItem.spedealflg" label="特殊处理标志"></v-text-field>
                    </v-col>

                    <v-col cols="12" sm="6" md="4">
                        <v-text-field v-model="editedItem.execrate" label="执行利率"></v-text-field>
                    </v-col>

                    <v-col cols="12" sm="6" md="4">
                        <v-text-field v-model="editedItem.intrate" label="利率"></v-text-field>
                    </v-col>


                   <v-col cols="12" sm="6" md="4">
                  <v-select :items="rcdstsItems" 
                  label="记录状态" 
                  v-model="editedItem.stsrcd"
                  item-text="name"
                  item-value="attributes"
                  ></v-select>
                  </v-col>
                   
                </v-row>
              </v-container>
            </v-card-text>

            <v-card-actions>
              <v-spacer></v-spacer>
              <v-btn color="blue darken-1" text @click="close">取消</v-btn>
              <v-btn color="blue darken-1" text @click="save">保存</v-btn>
            </v-card-actions>
          </v-card>
        </v-dialog>
      </v-toolbar>
    </template>
    <template v-slot:item.actions="{ item }">
      <v-icon small class="mr-2" @click="editItem(item)">mdi-pencil</v-icon>
      <v-icon small @click="deleteItem(item)">mdi-delete</v-icon>
    </template>
    <template v-slot:no-data>
      <v-btn color="primary" @click="initialize">Reset</v-btn>
    </template>

       <template v-slot:item.stsrcd="{ item }">
    
      <span v-for="s in rcdstsItems" key="s.id" v-if="s.attributes==item.stsrcd">{{s.name}}</span>
    </template>
  </v-data-table>
</template>

<script>
export default {
  data: () => ({
    thisSerseqn:'',
    chnelnoItems:[],
    moduleItems:[],
    rcdstsItems:[],
    acdealflgItems:[],
    crflgItems:[],
    tranentnoItems:[],
    dialog: false,
    brcItems:[],
      headers: [
      // { text: "银行号", value: "bankid" },
      { text: "所属系统", value: "subsys" },
      { text: "核算会计日期", value: "accdate" },
      { text: "核算会计流水号", value: "accseqno" },
      { text: "核心交易日期", value: "kltrndate" },
      { text: "核心流水号", value: "kltrnseq" },
      { text: "核心流水号序号", value: "klseqno" },
      { text: "会计分户记账标志", value: "klseqno" },
      { text: "交易金额", value: "tranamt" },
      { text: "产品代码", value: "prdcode" },
      { text: "事件代码", value: "entcode" },
      { text: "币种", value: "ccy" },
      { text: "客户号", value: "custno" },
      { text: "内部账号", value: "accno" },
      { text: "产品账号", value: "prdaccno" },
      { text: "借据编号", value: "debitno" },
      { text: "产品账号户名", value: "prdaccname" },
      // { text: "账簿项编号", value: "bookno" },
      // { text: "钞汇标志", value: "crflg" },
      // { text: "归属机构", value: "brcadsc" },
      // { text: "凭证号", value: "vouno" },
      // { text: "凭证种类", value: "voutyp" },
      // { text: "摘要码", value: "memono" },
      // { text: "摘要", value: "memo" },
      // { text: "对方账号", value: "accnoa" },
      // { text: "对方户名", value: "accnma" },
      // { text: "对方行号", value: "banknoa" },
      // { text: "对方行名", value: "banknma" },
      // { text: "对方币种", value: "ccya" },
      // { text: "对方钞汇标识", value: "crflga" },
      // { text: "待销账编号", value: "acchngno" },
      // {text: "待销账种类", value: "hngacctyp" },
      // { text: "待销账操作", value: "hngopflg" },
      // { text: "挂账到期日", value: "hngduedate" },
      // { text: "挂账金额", value: "hngamt" },
      // { text: "销账金额", value: "canamt" },
      // {text: "特殊清算标志", value: "speclsflg" },
      // { text: "特殊处理标志", value: "spedealflg" },
      // {text: "记录状态", value: "stsrcd" },
      {text: "操作", value: "actions", sortable: false }
    ],
    desserts: [],
    editedIndex: -1,
    editedItem: {
        bankid: "",
        subsys: "",
        accdate: "",
        accseqno: "",
        kltrndate: "",
        kltrnseq: "",
        klseqno: "",
        tranamt: "",
        prdcode: "",
        entcode: "",
        ccy: "",
        custno: "",
        accno: "",
        prdaccno: "",
        debitno: "",
        prdaccname: "",
        bookno: "",
        crflg: "0",
        brcadsc: "",
        vouno: "",
        voutyp: "",
        memono: "",
        memo: "",
        accnoa: "",
        accnma: "",
        banknoa: "",
        banknma: "",
        ccya: "",
        crflga: "0",
        acchngno: "",
        hngacctyp: "",
        hngopflg: "0",
        hngduedate: "",
        hngamt: "",
        canamt: "",
        speclsflg: "0",
        spedealflg: "0",
        stsrcd:"1",
    },
    defaultItem: {
        bankid: "",
        subsys: "",
        accdate: "",
        accseqno: "",
        kltrndate: "",
        kltrnseq: "",
        klseqno: "",
        tranamt: "",
        prdcode: "",
        entcode: "",
        ccy: "",
        custno: "",
        accno: "",
        prdaccno: "",
        debitno: "",
        prdaccname: "",
        bookno: "",
        crflg: "0",
        brcadsc: "",
        vouno: "",
        voutyp: "",
        memono: "",
        memo: "",
        accnoa: "",
        accnma: "",
        banknoa: "",
        banknma: "",
        ccya: "",
        crflga: "0",
        acchngno: "",
        hngacctyp: "",
        hngopflg: "0",
        hngduedate: "",
        hngamt: "",
        canamt: "",
        speclsflg: "0",
        spedealflg: "0",
        stsrcd:"1",
    }
  }),

  computed: {
    formTitle() {
      return this.editedIndex === -1 ? "新增" : "修改";
    }
  },

  watch: {
    dialog(val) {
      val || this.close();
    }
  },

  created() {
    this.initialize();
    this.getDict();
  },

  methods: {
    initialize() {
     this.axios
        .get("/acfm16/list")
        .then(response => {
          this.desserts = response.data.data;
        })
        .catch(response => {
          console.log(response.data.message);
        });
    },
     getDict(){
        this.axios
        .get("/dict/topName/渠道")
        .then(response => {
          this.chnelnoItems = response.data.data;
        })
        .catch(response => {
          console.log(response.data.message);
        });
        this.axios
        .get("/dict/topName/交易模块")
        .then(response => {
          this.moduleItems = response.data.data;
        })
        .catch(response => {
          console.log(response.data.message);
        });
        this.axios
        .get("/brcInfo/list")
        .then(response => {
          this.brcItems = response.data.data;
        })
        .catch(response => {
          console.log(response.data.message);
        });
        this.axios
        .get("/dict/topName/记录状态")
        .then(response => {
          this.rcdstsItems = response.data.data;
        })
        .catch(response => {
          console.log(response.data.message);
        });
        this.axios
        .get("/dict/topName/会计流水处理标志")
        .then(response => {
          this.acdealflgItems = response.data.data;
        })
        .catch(response => {
          console.log(response.data.message);
        });
      
      this.axios
        .get("/dict/topName/钞汇标识")
        .then(response => {
          this.crflgItems = response.data.data;
        })
        .catch(response => {
          console.log(response.data.message);
        });
        this.axios
        .get("/acfb19/list")
        .then(response => {
          this.tranentnoItems = response.data.data;
        })
        .catch(response => {
          console.log(response.data.message);
        });
        
    },
    editItem(item) {
      this.editedIndex = this.desserts.indexOf(item);
      this.editedItem = Object.assign({}, item);
      this.dialog = true;
    },

    

    deleteItem(item) {
      const index = this.desserts.indexOf(item);
      confirm("确定要删除此条记录吗?") &&
        this.axios.delete('/acfm16/'+item.id)
          .then(res=>{
            this.desserts.splice(index, 1); 
          })
        
    },

    close() {
      this.dialog = false;
      this.$nextTick(() => {
        this.editedItem = Object.assign({}, this.defaultItem);
        this.editedIndex = -1;
      });
    },

    save() {
       this.axios.post("/acfm16", this.$qs.stringify(this.editedItem)).then(res => {
          this.initialize();
          this.close();
      });
      
    }
  }
};
</script>